import type {
  ConsultOrderPreData,
  AllDep,
  ConsultOrderPreParams,
  Image,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'
import type {
  DoctorPage,
  PageParams,
  KnowledgeParams,
  KnowledgePage,
  FollowType,
  Patient
} from './../types/user'
import { request } from '@/utils/request'
// 查询推荐/减脂/饮食健康/关注页面--百科文章列表
export const getKnowledgePage = (params: KnowledgeParams) => {
  return request<KnowledgePage>('/patient/home/knowledge', 'GET', params)
}

// 关注的医生列表
export const getDoctorPage = (params: PageParams) => {
  return request<DoctorPage>('home/page/doc', 'GET', params)
}

// 关注的操作
export const followOrUnfollow = (id: string, type: FollowType = 'doc') => {
  return request('/like', 'POST', { id, type })
}

// 选择问诊科室
export const getAllDep = () => {
  return request<AllDep[]>('/dep/all', 'GET')
}

// 上传图片
export const uploadImage = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request<Image>('/upload', 'POST', formData)
}

// 预支付
export const getConsultOrderPre = (params: ConsultOrderPreParams) => {
  return request<ConsultOrderPreData>(
    '/patient/consult/order/pre',
    'GET',
    params
  )
}

// 患者详情
export const getPatientDetail = (id: string) => {
  return request<Patient>(`/patient/info/${id}`, 'GET')
}

// 生成订单
export const createConsultOrder = (data: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}
// 支付
export const createConsultOrderPay = (data: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'post', data)
}

// 订单详情
export const getConsultOrderDetail = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', {
    orderId
  })
}

// 未读消息
export const getMessageUnReadAll = () => {
  return request<number>('/patient/message/unRead/all', 'GET')
}

// 原始处方
export const getPrescriptionUrl = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET')
}
// 评价医生
export const evaluateDocOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: number
}) => {
  return request('/patient/order/evaluate', 'POST', data)
}

// 问诊记录
export const getConsultOrderList = (params: ConsultOrderListParams) => {
  return request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)
}

// 取消订单
export const cancelOrder = (id: string) => {
  return request(`/patient/order/cancel/${id}`, 'PUT')
}

// 删除订单
export const delOrder = (id: string) => {
  return request(`/patient/order/${id}`, 'DELETE')
}
